<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
       <%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="description" content="人生就是一部小说,记录生活的点滴" />
    <meta name="keywords" content="记录生活,小说人说,分享你的生活动态,订阅他人的分享" />
    <script>
    window._time = [Date.now()];
    </script>
    <link rel="stylesheet" href="/faceb-cupt/css/reset.min.css" />
    <link rel="stylesheet" href="/faceb-cupt/css/detail.min.css" />
    <link rel="stylesheet" href="/faceb-cupt/util/font-awesome-3.2.1/css/font-awesome.min.css" />
    
    <title>我的动态详情</title>
    <style type="text/css">
    .add-1{
        color: #333333;

    }
    .add-2{
        color: #0DC8C8;
    }
    .imgcon img{
        float: left;
        max-width: 150px;
        padding: 10px;

    }
    </style>
</head>

<body>
    <div class="page-header clearfix">
        <h1 class="page-header-title pull-left">${user.u_info}</h1>
        <div class="page-header-personal pull-right">
            <a href="/faceb-cupt/tpl/profile" class="personal-photo">
                <span class="name">${user.u_name}</span>
                <img src="http://172.18.106.98:8080/faceb-cupt/userlogo/users/${user.u_id }" alt="test" />
            </a>
        </div>
    </div>
    <div class="page-aside">
        <ul class="navbar">
            <li>
                <a href="/faceb-cupt/tpl/index" class="home">
                    <i class="icon-home"></i>
                </a>
                <a href="javascript:void(0)" class="js-gocenter">
                    <i class="icon-user"></i>
                </a>
            </li>
        </ul>
    </div>
    <div class="page-content">
        <div class="dongtai">
            <p class="add-2"><span class="author"></span><span class="time-ago"></span></p>
            <p class=""><span class="category fbold"></span><span class="content tem-detail add-1"></span></p>
            <div class="imgcon">
                
            </div>
            <div class="contrl-info">
                <span class="read-count"></span>
                <span class="pl-count"></span>
                <span class="like"></span>
            </div>
        </div>
        <div class="pinglun">
            <ul class="pinglun-list">
               
            </ul>
            <div class="comment">
                <div class="virtual hide">我也说一句</div>
                <div class="comment-box clearfix">
                    <textarea class="js-publictxt"></textarea>
                    <a href="javascript:void(0)" class='btn btn-primary fr js-public'>发表</a>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="/faceb-cupt/lib/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/faceb-cupt/js/lib/template.js"></script>
   <script type="text/javascript">
       var app={
        init:function(){
            app.render();
            app.bindEvent();
            app.getdata();
        },
        render:function(){



        },
        bindEvent:function(){
            $(".js-public").on("click",function(e){
                var txt=$(".js-publictxt").val();
                if(txt.length==0){
                    alert("快点添加你的评论吧，不能为空哟→_→");
                }else{
                    var nid=window.location.search.substring(window.location.search.indexOf("=")+1);
                    var sdata={
                        comment:txt,
                        nid:nid

                    };
                    console.log(sdata);
                    $.ajax({
                        url: '/faceb-cupt/comments/public',
                        dataType: "json",
                        contentType: "application/x-www-form-urlencoded; charset=utf-8",
                        type: 'POST',
                        data: sdata,
                    }).done(function(data){
                        if(data&&data.status=="0"){
                            window.location.reload();
                        }else{
                            console.log("public error");
                        }
                    })
                }


            });

            //go to  center
            $(".js-gocenter").on("click",function(e){
                var userid=document.cookie.split("=")[1];
                window.location.href="/faceb-cupt/tpl/center/users/"+userid;

            })

        },
        getdata:function(){
            var urldata=window.location.search.substring(window.location.search.indexOf("=")+1);
            $.ajax({
                url: '/faceb-cupt/news/' + urldata,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                type: 'POST',
                data: {},
            }).done(function(data){
                console.log(data);
                if(data&&data.status==0){
                    var comments=data.data.comments;
                    var news=data.data.news;
                    var pics=data.data.pics;
                    

                    app.render_detail(comments,news,pics);
                }
            })

        },
        render_detail:function(comments,news,pics){

            var t_detail=$(".tem-detail");

            t_detail.html(news.n_content);
            $(".like").text(news.n_like+"喜欢");
            $(".pl-count").text(comments.length+"评论");
            $(".read-count").text(news.n_viewcount+"阅读");
            $(".author").text(news.u_name);
            $(".time-ago").text(news.n_time);

            if(comments.length==0){
                $(".pinglun-list").hide();
            }else{
                window.comment=comments;
            }
            //pics
            var img_con=$(".imgcon");
            if(pics.length==0){
                img_con.hide();
            }else{
                for(var j=0,jlength=pics.length;j<jlength;j++){
                    var img_item=$("<img>");
                    img_item.attr("src",pics[j]["np_path"]);

                    img_con.append(img_item);
                }
            }

            //comments
            if(comments.length==0){
                 $(".pinglun-list").hide();
             }else{
                var pl_con=$(".pinglun-list");
                console.log("122");
                console.log(comments);
                for(var c=0,clength=comments.length;c<clength;c++){
                    var tx_img=comments[c]["image"];
                    var c_content=comments[c]["c_content"];
                    var c_id=comments[c]["c_id"];
                    var c_name=comments[c]["u_name"];

                    var c_time=comments[c]["c_time"];
                    var c_u_id=comments[c]["c_u_id"];
                    var pl_li=$("<li class='clearfix'><div class='img-con fl'><img src="+tx_img+"></div><div class='pinlun-info fl'><p><span class='name'>"+c_name+"</span><span>:</span><span>"+c_content+"</span></p><p class='time-info'>"+c_time+"</p></div></li>");
                    pl_con.append(pl_li);

                }

             }


        }

       }
       app.init();


   </script>
</body>

</html>
